<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>部门管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!-- 查询区域 -->
        <fieldset class="table-search-fieldset" >
            <div >
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">部门名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="deptName" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i></button>
                        </div>

                    </div>
                </form>
            </div>
        </fieldset>
        <!-- 查询区域 -->

        <!-- 列表区域 -->
        <script type="text/html" id="toolbarDemo">
           <div class="layui-btn-container">
                <button class="layui-btn data-add-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增 </button>
            </div>
        </script>
        
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="num_down">
            {{d.LAY_TABLE_INDEX+1}}
        </script>
        
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="delete">删除</a>
        </script>

    </div>
</div>

<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../js/app.js" charset="utf-8"></script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;

        var tableObj = table.render({
            elem: '#currentTableId',
            url: '/hrDept/list3page',
            method: 'get',
            toolbar: '#toolbarDemo',
            defaultToolbar: [],
            even: true,
            cols: [[
                {field:'num', title: '序号', width:60, align: 'center',templet:'#num_down'},
                {field: 'dept_name', width: 180, title: '部门名称'},
                {field: 'dept_code', width: 120, title: '部门编码', align: "center"},
                {field: 'leader_name', width: 120, title: '负责人'},
                {field: 'link_phone', width: 120, title: '联系电话'},
                {field: 'link_email', width: 150, title: '联系邮箱'},
                {field: 'create_time', width: 180, templet: function (d) {
                        if (d.create_time) {
                            return d.create_time.replace("T", " ");
                        }
                    }, title: '创建时间', align: 'center'},
                {field: 'remark', title: '备注'},
                {title: '操作', width: 150, toolbar: '#currentTableBar', align: "center", fixed:'right'}
            ]],
            limits: [20, 50, 100],
            limit: 20,
            page: true,
            height: 'full-105'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                },
                where: {
                	deptName : data.field.deptName,
                }
            });

            return false;
        });

     // toolbar监听事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加部门信息',
                    type: 2,
                    shade: 0.2,
                    area: ['75%', '75%'],
                    content: 'dept-edit.html',
                });
            }
        });
     
        // toolbar监听事件
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            
            if (obj.event === 'edit') {
                global_setLocalStorage("dept-list#object", data);
                
                var index = layer.open({
                    title: '编辑部门信息',
                    type: 2,
                    shade: 0.2,
                    area: ['75%', '75%'],
                    content: 'dept-edit.html',
                    success: function (layer, index) {
                    },
                });
            } else if (obj.event === 'delete') {
            	layer.confirm('确定删除该部门吗？',{title:'提示',icon: 3}, 
                    function (index) {
                        $.post("/hrDept/deleteDept", {id: data.id},
                            function(data) {
                                if(data.result=='ok'){
                                    alert_msg('删除成功！');
                                    layer.close(index);
                                    tableObj.reload();

                                }else{
                                    alert_msg('操作未成功，请稍后重试或联系管理员！',2,0);
                                }
    
                            }
                        );
                });
            }
            
            return false;
        });


    });
</script>

</body>
</html>
